package gen

import (
	"errors"
	"path"

	"gitee.com/zawei/yggdrasil/internal/yggdrasil/gen/generator"
	"gitee.com/zawei/yggdrasil/third_party/urfave/cli"
	"github.com/sirupsen/logrus"
)

var newCmd = &cli.Command{
	Name:    "new",
	Aliases: []string{"n"},
	Usage:   "Generate new project",
	Flags: []cli.Flag{
		&cli.StringFlag{Name: "gen_new_project_path", Value: path.Join("./")},
		&cli.StringFlag{Name: "gen_new_project_service", Value: "hello"},
		&cli.StringFlag{Name: "gen_new_project_module", Value: ""},
	},
	Action: func(ctx *cli.Context) error {
		args := ctx.Args().Slice()
		if len(args) == 0 {
			return errors.New("you must provide a name for the service")
		}
		g := generator.NewNewProject(args[0])
		if err := g.Generate(); err != nil {
			logrus.Error(err)
		}
		return nil
	},
}

func init() {
	genCmd.Subcommands = append(genCmd.Subcommands, newCmd)
}
